<script setup lang="ts">
import { ref } from 'vue';
import { createPinia } from 'pinia';
import AppHeader from './components/AppHeader.vue';
import ImageUploader from './components/upload/ImageUploader.vue';
import ImageGallery from './components/upload/ImageGallery.vue';
import StitchingControls from './components/stitching/StitchingControls.vue';
import StitchedImageViewer from './components/stitching/StitchedImageViewer.vue';
import RestorationControls from './components/restoration/RestorationControls.vue';
import RestoredImagesViewer from './components/restoration/RestoredImagesViewer.vue';
import { useStitchingStore } from './stores/stitchingStore';
import { useRestorationStore } from './stores/restorationStore';

// Initialize Pinia
createPinia();

const activeTab = ref('stitch');
const stitchingStore = useStitchingStore();
const restorationStore = useRestorationStore();

function handleTabChange(tab: string) {
  // 如果从还原标签切换到拼接标签，清空还原状态
  if (activeTab.value === 'restore' && tab === 'stitch') {
    restorationStore.clearAll();
  }

  // 如果从拼接标签切换到还原标签，清空已还原的图片（保留上传的图片和元数据）
  if (activeTab.value === 'stitch' && tab === 'restore') {
    restorationStore.clearRestoredImages();
  }

  activeTab.value = tab;
}
</script>

<template>
  <div class="app-container">
    <AppHeader @change-tab="handleTabChange" />

    <main class="main-content">
      <div v-if="activeTab === 'stitch'" class="stitch-tab">
        <ImageUploader />
        <ImageGallery />
        <StitchingControls />
        <StitchedImageViewer v-if="stitchingStore.stitchedImage" />
      </div>

      <div v-else-if="activeTab === 'restore'" class="restore-tab">
        <RestorationControls />
        <RestoredImagesViewer v-if="restorationStore.restoredImages.length > 0" />
      </div>
    </main>

    <footer class="app-footer">
      <p>拼好图 &copy; 2025</p>
      <a style="margin-right: 20px;" href="https://gitee.com/yuewusan/pinhaotu" target="_blank">gitee源代码</a>
      <a href="https://github.com/Aescde/pinhaotu" target="_blank">github源代码</a>
    </footer>
  </div>
</template>

<style>
:root {
  font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  font-weight: 400;

  color-scheme: light dark;
  color: rgba(0, 0, 0, 0.87);
  background-color: #ffffff;

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

* {
  box-sizing: border-box;
}
</style>

<style scoped>
.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Responsive styles */
@media (max-width: 768px) {
  .app-container {
    padding: 0 0.5rem;
  }
}

.main-content {
  flex: 1;
  padding: 2rem 0;
}

.app-footer {
  padding: 1rem 0;
  text-align: center;
  border-top: 1px solid #e0e0e0;
  margin-top: 2rem;
  color: #666;
}
</style>